home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_100 / 198_02 / st520.c < prev    next >
C/C++ Source or Header  |  1990-01-21  |  21KB  |  1,033 lines

  1. /*
  2.  
  3. The routines in this file provide support for the Atari 520 or 1040ST
  4. using VT52 emulation.  The I/O services are provided here as well.  It
  5. compiles into nothing if not a 520ST style device.
  6.  
  7. */
  8.  
  9. #define    termdef    1            /* don't define "term" external */
  10.  
  11. #include        <stdio.h>
  12. #include        "estruct.h"
  13. #include    "edef.h"
  14.  
  15. #if     ATARI & ST520 & MEGAMAX
  16. #include    <osbind.h>
  17. #include    <ctype.h>
  18.  
  19. #define LINEA_INIT 0xA000
  20. #define V_CEL_WR   -0x28
  21.  
  22. #define V_CEL_MY   -0x2a
  23. #define V_CEL_HT   -0x2e
  24. #define V_FNT_AD   -0x16
  25. #define V_OFF_AD   -0x0a
  26. #define V_DISAB    -346
  27.  
  28. #define NROW    25                      /* Screen size.                 */
  29. #define NCOL    80                      /* Edit if you want to.         */
  30. #define    MARGIN    8            /* size of minimim margin and    */
  31. #define    SCRSIZ    64            /* scroll size for extended lines */
  32. #define    NPAUSE    25            /* # times thru update to pause */
  33. #define BIAS    0x20                    /* Origin 0 coordinate bias.    */
  34. #define ESC     0x1B                    /* ESC character.               */
  35. #define BEL     0x07                    /* ascii bell character         */
  36.  
  37. extern  int     ttopen();               /* Forward references.          */
  38. extern  int     ttgetc();
  39. extern  int     ttputc();
  40. extern  int     ttflush();
  41. extern  int     ttclose();
  42. extern  int     st520move();
  43. extern  int     st520eeol();
  44. extern  int     st520eeop();
  45. extern  int     st520beep();
  46. extern  int     st520open();
  47. extern    int    st520close();
  48. extern    int    st520rev();
  49. extern  int st520kopen();
  50. extern  int st520kclose();
  51. extern    int st520chgrez();
  52.  
  53. #if    COLOR
  54. extern    int    st520fcol();
  55. extern    int    st520bcol();
  56.  
  57. int        cfcolor = -1;        /* current fg (character) color */
  58. int        cbcolor = -1;        /* current bg color */
  59. int        oldpal[8];        /* pallette when emacs was invoked */
  60. int        newpal[8] = {        /* default emacs pallette */
  61.     0x000, 0x700, 0x070, 0x770, 0x007, 0x707, 0x077, 0x777};
  62. #endif
  63.  
  64. int STncolors = 0;        /* number of colors  */
  65. int STrez;            /* physical screen resolution */    
  66.  
  67. /*
  68.  * Dispatch table. All the
  69.  * hard fields just point into the
  70.  * terminal I/O code.
  71.  */
  72. TERM    term    = {
  73.         NROW-1,
  74.         NCOL,
  75.     MARGIN,
  76.     MARGIN,
  77.     SCRSIZ,
  78.     NPAUSE,
  79.         &st520open,
  80.         &st520close,
  81.     &st520kopen,
  82.     &st520kclose,
  83.         &ttgetc,
  84.         &ttputc,
  85.         &ttflush,
  86.         &st520move,
  87.         &st520eeol,
  88.         &st520eeop,
  89.         &st520beep,
  90.         &st520rev
  91. #if    MULTREZ
  92.     , &st520chgrez
  93. #endif
  94. #if    COLOR
  95.     , &st520fcol,
  96.     &st520bcol
  97. #endif
  98. };
  99.     struct KBDvecs {
  100.         int (*midivec) ();
  101.         int (*vkbderr) ();
  102.         int (*vmiderr) ();
  103.         int (*statvec) ();
  104.         int (*mousevec) ();
  105.         int (*clockvec) ();
  106.         int (*joyvec) ();
  107.         int (*midisys) ();
  108.         int (*ikbdsys) ();
  109.     };
  110.     struct Param {
  111.         char topmode;
  112.         char buttons;
  113.         char xparam;
  114.         char yparam;
  115.         int xmax,ymax;
  116.         int xinitial,yinitial;
  117.     };
  118.     struct KBDvecs *kbdvecs;
  119.     struct Param *paramp;
  120.     char kbdcmds[25];
  121.  
  122. st520move(row, col)
  123. {
  124.         ttputc(ESC);
  125.         ttputc('Y');
  126.         ttputc(row+BIAS);
  127.         ttputc(col+BIAS);
  128. }
  129.  
  130. st520eeol()
  131. {
  132.         ttputc(ESC);
  133.         ttputc('K');
  134. }
  135.  
  136. st520eeop()
  137. {
  138.  
  139. #if    COLOR
  140.         st520fcol(gfcolor);
  141.         st520bcol(gbcolor);
  142. #endif
  143.         ttputc(ESC);
  144.         ttputc('J');
  145. }
  146.  
  147. st520rev(status)    /* set the reverse video state */
  148.  
  149. int status;    /* TRUE = reverse video, FALSE = normal video */
  150.  
  151. {
  152.  
  153.     if(status) {
  154.         ttputc(ESC);
  155.         ttputc('p');
  156.     }
  157.     else {
  158.         ttputc(ESC);
  159.         ttputc('q');
  160.     }
  161. }
  162.  
  163. #if    COLOR
  164. st520fcol(color)
  165. int color;    
  166. {
  167.         if(color == cfcolor || !STncolors)
  168.             return;
  169.         else {
  170.  
  171.             ttputc(ESC);
  172.             ttputc('b');
  173.             ttputc(color & 0x0f);
  174.             cfcolor = color;
  175.         }
  176. }
  177.  
  178. st520bcol(color)
  179. int color;
  180. {
  181.         if(color == cbcolor || !STncolors)
  182.             return;
  183.         else {
  184.             ttputc(ESC);
  185.             ttputc('c');
  186.             ttputc(color & 0x0f);
  187.             cbcolor = color;
  188.         }
  189.  
  190. }
  191. #endif
  192.  
  193. st520beep()
  194. {
  195. #ifdef    BEL
  196.         ttputc(BEL);
  197.         ttflush();
  198. #endif
  199. }
  200.  
  201. st520open()
  202. {
  203.     int i,j,k;
  204.     long phys, log;    /* screen bases */
  205.     
  206. /* IMPORTANT: it is ABSOLUTELY necessary that the default resolution be the
  207.  *    largest possible so that display will allocate (malloc) the maximum
  208.  *    size for the VIDEO arrray
  209.  */
  210.     STrez = Getrez();
  211.     switch(STrez) {
  212.         case 0: /* low res 25x40 16 colors */
  213.             phys = Physbase();
  214.             log  = Logbase();
  215.             Setscreen(log, phys, 1);
  216.             STrez = 1;
  217.             /* fall thru to med res */
  218.  
  219.         case 1: /* med res 25x80 4 colors */
  220.             term.t_nrow = 25 - 1;
  221.             term.t_ncol  = 80;
  222.             grez = 1;
  223. #if    COLOR
  224.             STncolors = 4;
  225.             for(i=0;i<8;i++) {
  226.                 oldpal[i] = Setcolor(i,newpal[i]);
  227.             }
  228. #endif
  229.             break;
  230.         case 2: /* high res 25x80 no colors */
  231.             term.t_nrow  = 40 - 1;
  232.             term.t_ncol  = 80;
  233.             grez = 2;
  234.             make_8x10(); /* create a smaller font */
  235.             set_40();    /* and go to 40 line mode */
  236. #if    COLOR
  237.             STncolors = 0;
  238. #endif
  239.             break;
  240.     }
  241.  
  242.     revexist = TRUE;
  243.     eolexist = TRUE;
  244.     paramp = (struct Param *)malloc(sizeof(struct Param));
  245.     kbdvecs = (struct KBDvecs *)Kbdvbase();
  246.     paramp -> topmode = 0;
  247.     paramp -> buttons = 4;
  248.     paramp -> xparam = 8;
  249.     paramp -> yparam = 10;
  250.     paramp -> xmax = 79;
  251.     paramp -> ymax = 23;
  252.     paramp -> xinitial = 0;
  253.     paramp -> yinitial = 0;
  254.     Initmous(1,paramp,kbdvecs -> mousevec);
  255.  
  256.     i = 0;
  257.     kbdcmds[i++] = 0x0a;    /*set mouse keycode mode */
  258.     kbdcmds[i++] = 0x08;
  259.     kbdcmds[i++] = 0x0a;
  260.     Ikbdws(i-1,&kbdcmds[0]);
  261.     Cursconf(1,0);
  262.     Cursconf(3,0);
  263.     Cconout(27);Cconout('E');
  264.         ttopen();
  265. }
  266.  
  267. st520close()
  268.  
  269. {
  270.     int i,j,k;
  271.  
  272.     i = 0;
  273.     kbdcmds[i++] = 0x80;    /*reset mouse keycode mode */
  274.     kbdcmds[i++] = 0x01;
  275.     Ikbdws(i-1,&kbdcmds[0]);
  276.     if(grez == 2 && STrez == 2) /* b/w monitor in 40 row mode */
  277.         restore();
  278.  
  279. #if        COLOR
  280.     for(i=0;i<STncolors;i++)
  281.         Setcolor(i,oldpal[i]);
  282. #endif
  283.     Cconout(27);Cconout('E');
  284.     paramp -> buttons = 0;
  285.     Initmous(2,paramp,kbdvecs -> mousevec);
  286.     i = 0;
  287.     kbdcmds[i++] = 0x80;    /*reset the keyboard*/
  288.     kbdcmds[i++] = 0x01;
  289.     Ikbdws(i-1,&kbdcmds[0]);
  290.     Cursconf(1,0);
  291.     ttclose();
  292. }
  293. st520kopen()
  294. {
  295.  
  296. }
  297. st520kclose()
  298. {
  299.  
  300. }
  301.  
  302. st520chgrez(nurez)
  303. int nurez;
  304. {
  305.     int ierr, i, j ,k;
  306.     long phys, log;    /* screen bases */
  307.     char dum[80]; /* for debugging only */
  308.         
  309.     if(grez == nurez)
  310.         return(TRUE);
  311.         
  312.     if(STrez == 2) { /* b/w monitor-only allow hi | med rez */
  313.         switch(nurez) {
  314.             case 2: /* high res */
  315.                 term.t_nrow  = 40 - 1;
  316.                 term.t_ncol  = 80;
  317.                 make_8x10(); /* create a smaller font */
  318.                 set_40();    /* and go to 40 line mode */
  319.                 grez = 2;
  320.                 sgarbf = TRUE;
  321.                 onlywind(1,1);
  322.                 break;
  323.             case 1: /* med res */
  324.                 term.t_nrow  = 25 - 1;
  325.                 term.t_ncol  = 80;
  326.                 restore();
  327.                 grez = 1;
  328.                 sgarbf = TRUE;
  329.                 onlywind(1,1);
  330.                 break;
  331.             default:
  332.                 mlwrite("Invalid resolution");
  333.                 return(FALSE);
  334.                 break;
  335.         }
  336.     }
  337.     else { /* color monitor-only allow low | medium resolution */
  338.         phys = Physbase();
  339.         log  = Logbase();
  340.         switch(nurez) {
  341.             case 1:
  342.                 term.t_nrow  = 25 - 1;
  343.                 term.t_ncol  = 80;
  344.                 Setscreen(log, phys, 1);
  345.                 STncolors = 4;
  346.                 grez = 1;
  347.                 sgarbf = TRUE;
  348.                 onlywind(1,1);
  349.                 break;
  350.             case 0:
  351.                 term.t_nrow  = 25 - 1;
  352.                 term.t_ncol  = 40;
  353.                 Setscreen(log, phys, 0);
  354.                 STncolors = 8;
  355.                 grez = 0;
  356.                 sgarbf = TRUE;
  357.                 onlywind(1,1);
  358.                 break;
  359.             default:
  360.                 mlwrite("%Invalid resolution");
  361.                 return(FALSE);
  362.                 break;
  363.         }
  364.     }
  365. }            
  366.  
  367. STcurblink(onoff)
  368. int onoff;
  369. {
  370.     if(onoff)
  371.         Cursconf(2,0);
  372.     else
  373.         Cursconf(3,0);
  374. }
  375.  
  376.  
  377. char parm_save[28];
  378. long fnt_8x10[640];
  379.  
  380. make_8x10()
  381. {
  382.     int i,j,k;
  383.     long savea23[2];
  384.     
  385.     for(i=0;i<640;i++)
  386.         fnt_8x10[i] = 0;
  387.         
  388.     asm {
  389.     movem.l    A2-A3,savea23(A6)
  390.     
  391.     dc.w    LINEA_INIT        ;A1 -> array of font headers
  392.  
  393.     lea    parm_save(A4),A2    ;A2 -> parameters savearea
  394.     move.l    V_OFF_AD(A0),(A2)+
  395.     move.l    V_FNT_AD(A0),(A2)+
  396.     move.w    V_CEL_HT(A0),(A2)+
  397.     move.w    V_CEL_MY(A0),(A2)+
  398.     move.w    V_CEL_WR(A0),(A2)+
  399.  
  400.  
  401.     move.l    04(A1),A1        ; A1 -> 8x8 font header
  402.     move.l    76(A1),A2        ; A2 -> 8x8 font data
  403.     lea    fnt_8x10+0x100(A4),A3    ; A3 -> 2nd line of font buffer
  404.     move.w    #0x200-1,D0        ; D0 <- longword counter for font xfer
  405.  
  406. fnt_lo